package gdut.jmxywz.action;

import gdut.jmxywz.been.ImageInfo;
import gdut.jmxywz.been.Info;
import gdut.jmxywz.been.Teacher;
import gdut.jmxywz.util.PageModel;

import java.io.UnsupportedEncodingException;
import java.util.Iterator;
import java.util.List;

import com.opensymphony.xwork2.ActionContext;

@SuppressWarnings("serial")
public class NewsAction extends BaseAction {
	
	private  static final String  TEACHER_SESSION_KEY = "teacherSessionKey";

	private Info     info;
	private Teacher  teacher;
	
	private String   newsType;
	private String   auditing="";
	private  String   searchWhere="";//拼接查询条件跳页
	
	
	private  String   where_search=""; //查询条件
	private  String   where_value="";
	private  String   like="" ;
	
	//分页
	private int        currentPage=1;
	private int        pageSize=5;
	private String     nextPage;
	private PageModel  pm;
	
	
	
	public Info getInfo() {
		return info;
	}

	public void setInfo(Info info) {
		this.info = info;
	}
    
	
	public Teacher getTeacher() {
		return teacher;
	}

	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}

	public String getSearchWhere() {
		return searchWhere;
	}

	public void setSearchWhere(String searchWhere) {
		this.searchWhere = searchWhere;
	}

	public String getAuditing() {
		return auditing;
	}

	public void setAuditing(String auditing) {
		this.auditing = auditing;
	}

	public String getNewsType() {
		return newsType;
	}

	public void setNewsType(String newsType) {
		this.newsType = newsType;
	}

	public String getWhere_search() {
		return where_search;
	}

	public void setWhere_search(String whereSearch) {
		where_search = whereSearch;
	}

	public String getWhere_value() {
		return where_value;
	}

	public void setWhere_value(String where_value)throws UnsupportedEncodingException  {
	     this.where_value =new String(where_value.getBytes("ISO-8859-1"),"utf-8");
	}

	public String getLike() {
		return like;
	}

	public void setLike(String like) {
		this.like = like;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public String getNextPage() {
		return nextPage;
	}

	public void setNextPage(String nextPage) {
		this.nextPage = nextPage;
	}

	public PageModel getPm() {
		return pm;
	}

	public void setPm(PageModel pm) {
		this.pm = pm;
	}

	/***
	 *  ------------Add 发布信息
	 * 
	 */
	
	public String Add() throws Exception{
   
        teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);

		//先插入info表
		boolean b= false;
		info.setTeacherByInfoEditer(teacher);
//		if("".equals(newsType)||newsType==null){
//			System.out.println("----------------没有选择新闻类型---------------");
//			
//			return "error";
//		}
//		
		
		 //判断信息内容、发布者、标题是否为空，
		if("".equals(info.getInfoTitle())||"".equals(info.getInfoContext())||"".equals(info.getInfoSender())){
			
			return "error";
		}
		
		b= this.getCommonService().saveObject(info);
	   
	   //滚动新闻获取第一张图片地址。
	   if("图片新闻".equals(newsType)){
		   String imageUrl= "";
		   int count1 = info.getInfoContext().indexOf("<img");
		   System.out.println("----"+count1);
		   int count2=info.getInfoContext().indexOf("src=\"");
		   System.out.println("----"+count2);
		   if(count1<count2){
			   int count3=info.getInfoContext().indexOf("\"", count2)+1;
			   int count4=info.getInfoContext().indexOf("\"", count3);
			   System.out.println("----"+count3);
			   System.out.println("----"+count4);
		      for(int i=count3;i<count4;i++){
		    	  imageUrl = imageUrl+info.getInfoContext().charAt(i);
		  }
		      System.out.println("-----------"+imageUrl);
		  }
		   if("".equals(imageUrl)){
			   
			   System.out.println("没有找到图片");
			   //将发布的新闻删除
			   this.getCommonService().deleteObject(info);
			   
			   return "error";
		   }
		   
		   ImageInfo imageInfo = new ImageInfo();
		   
		   imageInfo.setImageName(info.getInfoTitle());
		   imageInfo.setImageUrl(imageUrl);
		   imageInfo.setInfo(info);
		   
		   boolean b2=this.getCommonService().saveObject(imageInfo);
		   
		   if(b2){
			   System.out.println("---------");
		   }
		   
		 
	   }
		

		if(b)
		{
			return "NewsAdd";
		}else{
			return  "error";
		}
		
	}
	
	/***
	 * List 后台最新所有通知列表
	 * 
	 */
      public String List() throws Exception{
    	  
    	  String hql =" from Info where  infoType=2 and auditing !=0";
    	  String[] parem = null;
    	  
    	  String  search_parameter = "";
    	  String en_where_value="";
    	  
    	  nextPage ="newsList.action" ;
    	  if(!"".equals(where_value)&&where_value!=null){
    		  
    		  en_where_value=java.net.URLEncoder.encode(where_value, "utf-8");//URL编码转换

    		  System.out.println("++++-- "+where_value);
    		  if(like.equals("like"))
    		  {
             	   hql =hql+"and "+where_search+" like '%"+where_value+"%'";
    		  }else{
    			  hql = hql +"and  "+where_search+" = '"+where_value+"'";
    		  }
    		  
    	  }
    	  //查询条件
    	  search_parameter="&where_search="+ where_search+"&like="+like+"&where_value="+en_where_value;
    	  
    	  hql = hql +" and auditing != 0";
    	  
    	  hql = hql +" order by infoTime desc,infoId desc,auditing desc";
    	  
    	  pm = new PageModel();
    	  
    	  pm=this.getCommonService().findPage(hql, parem, currentPage, pageSize, nextPage,search_parameter);
    	  System.out.print(pm);
    	  System.out.print(hql);
    	  return "NewsList";
      }
      
      /*public String List1() throws Exception{
    	  
    	  String hql =" from Info where  infoType=2 and auditing != 0";
    	  String[] parem = null;
    	  
    	  String  search_parameter = "";
    	  String en_where_value="";
    	  
    	  nextPage ="newsList1.action" ;
    	  if(!"".equals(where_value)&&where_value!=null){
    		  
    		  en_where_value=java.net.URLEncoder.encode(where_value, "utf-8");//URL编码转换

    		  System.out.println("++++-- "+where_value);
    		  if(like.equals("like"))
    		  {
             	   hql =hql+"and "+where_search+" like '%"+where_value+"%'";
    		  }else{
    			  hql = hql +"and  "+where_search+" = '"+where_value+"'";
    		  }
    		  
    	  }
    	  //查询条件
    	  search_parameter="&where_search="+ where_search+"&like="+like+"&where_value="+en_where_value;
    	  
    	  hql = hql +" and auditing != 0";
    	  
    	  hql = hql +" order by infoTime desc,infoId desc,auditing desc";
    	  
    	  pm = new PageModel();
    	  
    	  pm=this.getCommonService().findPage(hql, parem, currentPage, pageSize, nextPage,search_parameter);
    	  System.out.print(pm);
    	  System.out.print(hql);
    	  return "NewsList1";
      }
      */
     /* public String List2() throws Exception{
    	  
    	  String hql =" from Info where  infoType=2 and auditing != 0";
    	  String[] parem = null;
    	  
    	  String  search_parameter = "";
    	  String en_where_value="";
    	  
    	  nextPage ="newsList2.action" ;
    	  if(!"".equals(where_value)&&where_value!=null){
    		  
    		  en_where_value=java.net.URLEncoder.encode(where_value, "utf-8");//URL编码转换

    		  System.out.println("++++-- "+where_value);
    		  if(like.equals("like"))
    		  {
             	   hql =hql+"and "+where_search+" like '%"+where_value+"%'";
    		  }else{
    			  hql = hql +"and  "+where_search+" = '"+where_value+"'";
    		  }
    		  
    	  }
    	  //查询条件
    	  search_parameter="&where_search="+ where_search+"&like="+like+"&where_value="+en_where_value;
    	  
    	  hql = hql +" and auditing != 0";
    	  
    	  hql = hql +" order by infoTime desc,infoId desc,auditing desc";
    	  
    	  pm = new PageModel();
    	  
    	  pm=this.getCommonService().findPage(hql, parem, currentPage, pageSize, nextPage,search_parameter);
    	  System.out.print(pm);
    	  System.out.print(hql);
    	  return "NewsList2";
      }*/
      
     public String List3() throws Exception{
    	  
    	  String hql =" from Info where  infoType=2 and auditing != 0";
    	  String[] parem = null;
    	  
    	  String  search_parameter = "";
    	  String en_where_value="";
    	  
    	  nextPage ="newsList3.action" ;
    	  if(!"".equals(where_value)&&where_value!=null){
    		  
    		  en_where_value=java.net.URLEncoder.encode(where_value, "utf-8");//URL编码转换

    		  System.out.println("++++-- "+where_value);
    		  if(like.equals("like"))
    		  {
             	   hql =hql+"and "+where_search+" like '%"+where_value+"%'";
    		  }else{
    			  hql = hql +"and  "+where_search+" = '"+where_value+"'";
    		  }
    		  
    	  }
    	  //查询条件
    	  search_parameter="&where_search="+ where_search+"&like="+like+"&where_value="+en_where_value;
    	  
    	  hql = hql +" and auditing != 0";
    	  
    	  hql = hql +" order by infoTime desc,infoId desc,auditing desc";
    	  
    	  pm = new PageModel();
    	  
    	  pm=this.getCommonService().findPage(hql, parem, currentPage, pageSize, nextPage,search_parameter);
    	  System.out.print(pm);
    	  System.out.print(hql);
    	  return "NewsList3";
      }
      /***
       * 
       * 列表自己发布的Info
       * @return
       * @throws Exception
       */
   
        public String ListSelf() throws Exception{
        	
          teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);
      	  
      	  String hql =" from Info info where  info.infoType=2 and info.teacherByInfoEditer.teacherId="+teacher.getTeacherId();
      	  
      	  String[] parem = null;
      	  
    	  String  search_parameter = "";
    	  String en_where_value="";
    	  
      	  
      	  nextPage ="newsListSelf.action" ;
      	  
      	  if(!"".equals(where_value)&&where_value!=null){
      		  
      		  System.out.println("++++-- "+where_value);
      		  if(like.equals("like"))
      		  {
               	   hql =hql+"and "+where_search+" like '%"+where_value+"%'";
               	   
               	   
      		  }else{
      			  hql = hql +"and  "+where_search+" = '"+where_value+"'";
      		  }
      		  
      	  }
      	  
      	  //查询条件
      	 search_parameter="&where_search="+ where_search+"&like="+like+"&where_value="+en_where_value;
   	  
      	  
      	  hql = hql +" order by infoTime desc,infoId desc";
      	  
      	  pm = new PageModel();
      	  
      	  pm=this.getCommonService().findPage(hql, parem, currentPage, pageSize, nextPage,search_parameter);
      	  
      	  return "NewsListSelf";
      	  
        }
        //
        
        public String ListSelf1() throws Exception{
        	
            teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);
        	  
        	  String hql =" from Info info where  info.infoType=2 and info.teacherByInfoEditer.teacherId="+teacher.getTeacherId();
        	  
        	  String[] parem = null;
        	  
      	  String  search_parameter = "";
      	  String en_where_value="";
      	  
        	  
        	  nextPage ="newsListSelf1.action" ;
        	  
        	  if(!"".equals(where_value)&&where_value!=null){
        		  
        		  System.out.println("++++-- "+where_value);
        		  if(like.equals("like"))
        		  {
                 	   hql =hql+"and "+where_search+" like '%"+where_value+"%'";
                 	   
                 	   
        		  }else{
        			  hql = hql +"and  "+where_search+" = '"+where_value+"'";
        		  }
        		  
        	  }
        	  
        	  //查询条件
        	 search_parameter="&where_search="+ where_search+"&like="+like+"&where_value="+en_where_value;
     	  
        	  
        	  hql = hql +" order by infoTime desc,infoId desc";
        	  
        	  pm = new PageModel();
        	  
        	  pm=this.getCommonService().findPage(hql, parem, currentPage, pageSize, nextPage,search_parameter);
        	  
        	  return "NewsList1";
        	  
          }
      
      
	/***
	 * 
	 *   Detail  显示单条信息详细
	 */
      
	public String Detail() throws Exception{
    	  
    	
    	  info =(Info)this.getCommonService().findByIntId(info.getInfoId(), "gdut.jmxywz.been.Info");
    	  //更新阅读次数，加一
    	  info.setInfoReadtimes(info.getInfoReadtimes()+1);
    	  
    	  this.getCommonService().updateObject(info);
    	  
    	  //查找公告相应的附件
    	  
    	  return "NewsDetail";
      }
	 

	
	
	/***
	 * Auditing 审核通知列表
	 * 
	 */
	  public String Auditing () throws Exception{
		  
		  
		  String hql ="from Info where infoType = 2";
    	  String[] parem =null;
    	  String  search_parameter = "";
          String swhere_value = where_value;
   	      
          
    	  String en_where_value="";
    	  
    	  if(!"".equals(where_value)&&where_value!=null){
    	  
    		  if(like.equals("like"))
    		  {
    			
    			  System.out.println("fanhuid == "+where_value);
             	   hql =hql+"and "+where_search+" like '%"+swhere_value+"%'";
             	   System.out.println("====++++"+where_value);
             	   en_where_value=java.net.URLEncoder.encode(where_value,"utf-8");//URL编码转换
             	  
             	  
    		  }else{
//    			  where_value = java.net.URLDecoder.decode(where_value);

    			  hql = hql +"and "+where_search+" = '"+where_value+"'";

    	    	  en_where_value=java.net.URLEncoder.encode(where_value,"utf-8");//URL编码转换
    		  }
    		  
         	  System.out.println("------------++ "+search_parameter);
    	  }

    	  
    	  if(info==null||info.getAuditing()==null) {
    		  
    		  nextPage ="newsAuditing.action" ;
    	
    		  hql =hql + " order by auditing asc ,infoTime desc, infoId desc ";
    		  
    	  } else{
    		 
    	      hql =hql +"and auditing="+info.getAuditing()+" order by  auditing  asc ,infoTime desc,infoId desc  ";
    	      nextPage ="newsAuditing.action?auditing=0&" ;
    	    	
    	  }
    	  
    	  System.out.println("=============  "+where_value);
    	  System.out.println("============= "+where_search);
    	  System.out.println("------------- " +like);
    	  

		   search_parameter="&where_search="+ where_search+"&like="+like+"&where_value="+en_where_value;
    	  
		   System.out.println("---"+search_parameter);
		   System.out.println("---"+hql);
    	   pm = new PageModel();
    	  
    	  System.out.println("hql222---"+hql);
    	  pm=this.getCommonService().findPage(hql,parem, currentPage, pageSize, nextPage,search_parameter);
    	   System.out.println("---------------------"+pm.getTotalCount());
    	   System.out.println(pm);
		  return "NewsAuditing";
	  }
	  
    public String Auditing1 () throws Exception{
		  
		  
		  String hql ="from Info where infoType = 2";
    	  String[] parem =null;
    	  String  search_parameter = "";
          String swhere_value = where_value;
   	      
          
    	  String en_where_value="";
    	  
    	  if(!"".equals(where_value)&&where_value!=null){
    	  
    		  if(like.equals("like"))
    		  {
    			
    			  System.out.println("fanhuid == "+where_value);
             	   hql =hql+"and "+where_search+" like '%"+swhere_value+"%'";
             	   System.out.println("====++++"+where_value);
             	   en_where_value=java.net.URLEncoder.encode(where_value,"utf-8");//URL编码转换
             	  
             	  
    		  }else{
//    			  where_value = java.net.URLDecoder.decode(where_value);

    			  hql = hql +"and "+where_search+" = '"+where_value+"'";

    	    	  en_where_value=java.net.URLEncoder.encode(where_value,"utf-8");//URL编码转换
    		  }
    		  
         	  System.out.println("------------++ "+search_parameter);
    	  }

    	  
    	  if(info==null||info.getAuditing()==null) {
    		  
    		  nextPage ="newsAuditing1.action" ;
    	
    		  hql =hql + " order by auditing asc ,infoTime desc, infoId desc ";
    		  
    	  } else{
    		 
    	      hql =hql +"and auditing="+info.getAuditing()+" order by  auditing  asc ,infoTime desc,infoId desc  ";
    	      nextPage ="newsAuditing1.action?auditing=0&" ;
    	    	
    	  }
    	  
    	  System.out.println("=============  "+where_value);
    	  System.out.println("============= "+where_search);
    	  System.out.println("------------- " +like);
    	  

		   search_parameter="&where_search="+ where_search+"&like="+like+"&where_value="+en_where_value;
    	  
		   System.out.println("---"+search_parameter);
		   System.out.println("---"+hql);
    	   pm = new PageModel();
    	  
    	  System.out.println("hql222---"+hql);
    	  pm=this.getCommonService().findPage(hql,parem, currentPage, pageSize, nextPage,search_parameter);
    	   System.out.println("---------------------"+pm.getTotalCount());
    	   System.out.println(pm);
		  return "NewsList2";
	  }
	
	
	/***
	 * Inside  院内公布
	 * 
	 */
	  public String Inside() throws Exception{
		  
	     teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);

    	  info =(Info)this.getCommonService().findByIntId(info.getInfoId(), "gdut.jmxywz.been.Info");
    	  //将信息审核为对院内公布 ，即设置auditing为1；
    	  info.setAuditing("1");
    	  info.setTeacherByInfoAssessor(teacher);
    	  this.getCommonService().updateObject(info);
    	  
		  return "NewsInside";
	  }
	  
	
    /***
     *   Outside 对外公布
     */
    public String Outside() throws Exception{
		  
	      teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);
    	  
    	  info =(Info)this.getCommonService().findByIntId(info.getInfoId(), "gdut.jmxywz.been.Info");
    	  //将信息审核为对院内公布 ，即设置auditing为1；
    	  info.setAuditing("2");
    	  
    	  info.setTeacherByInfoAssessor(teacher);
    	  this.getCommonService().updateObject(info);
    	   
		  return "NewsOutside";
	  }
	
	/***
	 * 
	 *    Notallow 不通过
	 */
    public String Notallow() throws Exception{
    	
	  teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);

  	  info =(Info)this.getCommonService().findByIntId(info.getInfoId(), "gdut.jmxywz.been.Info");
  	  //将信息审核为对院内公布 ，即设置auditing为1；
  	  info.setAuditing("3");
  	  info.setTeacherByInfoAssessor(teacher);
  	  this.getCommonService().updateObject(info);
  	  
		  return "NewsNotallow";
	  }
	
    
    
	
	/***
	 * 
	 *    Rollback 未审核
	 */
    public String Rollback() throws Exception{
		  
		 teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);

    	  info =(Info)this.getCommonService().findByIntId(info.getInfoId(), "gdut.jmxywz.been.Info");
    	  //将信息审核为对院内公布 ，即设置auditing为1；
    	  info.setAuditing("0");
    	  info.setTeacherByInfoAssessor(teacher);
    	  
    	  this.getCommonService().updateObject(info);
    	  
  		  return "NewsRollback";
  	  }
    
    
    /***
     * 非管理员修改
     * @return
     * @throws Exception
     */
  
    public String ModifySelfShow() throws Exception{
 	 
	     teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);
	   
	   	 info =(Info)this.getCommonService().findByIntId(info.getInfoId(), "gdut.jmxywz.been.Info");
	       
	  	 if(!info.getTeacherByInfoEditer().getTeacherId().equals(teacher.getTeacherId())){
			
			System.out.println("没有修改的权限");
			
			return "error";
		}
	   	  if(!"0".equals(info.getAuditing())){
	   		  
	   		System.out.println("已通过审核，不能在修改！");
	   		
	   		return "error";
	   	  }
	   	  
	   	  System.out.println("-------------"+info.getInfoTitle());
	
	   	 
	 return "NewsModifyShowSelf";
}
	
	/***
	 * 
	 *  ModifyShow 修改时显示单体记录
	 */
    
	public String ModifyShow() throws Exception{
    	 
		   	  
		   	  //查找相应的通知
		   	  info =(Info)this.getCommonService().findByIntId(info.getInfoId(), "gdut.jmxywz.been.Info");
		       
		   	  System.out.println("-------------"+info.getInfoTitle());
		  
    	 return "NewsModifyShow";
     }
    
	
	/***
	 * 
	 *   Modify 修改 
	 *   
	 */
	
    public  String Modify() throws Exception {

		boolean b=false;
		System.out.println(info.getInfoId());
		Info info1 = (Info)this.getCommonService().findByIntId(info.getInfoId(), "gdut.jmxywz.been.Info");
		
		System.out.println("+++++++++++");
		System.out.println("+++++++++++"+info.getAuditing());
		info1.setAuditing(info.getAuditing());
		info1.setInfoContext(info.getInfoContext());
		info1.setInfoSender(info.getInfoSender());
		info1.setInfoTime(info.getInfoTime());
		info1.setInfoTitle(info.getInfoTitle());
		
		System.out.println("+++++++++++"+newsType);
		
//		if(newsType.equals("专题新闻")){
		//判断信息内容、发布者、标题是否为空，
		if("".equals(info1.getInfoTitle())||"".equals(info1.getInfoContext())||"".equals(info1.getInfoSender())){
			
			return "error";
		}
			b= this.getCommonService().updateObject(info1);
			
	   //滚动新闻获取第一张图片地址。
	   if("图片新闻".equals(newsType)){

		   String imageUrl= "";
		   int count1 = info.getInfoContext().indexOf("<img");
		   System.out.println("----"+count1);
		   int count2=info.getInfoContext().indexOf("src=\"");
		   System.out.println("----"+count2);
		   if(count1<count2){
			   int count3=info.getInfoContext().indexOf("\"", count2)+1;
			   int count4=info.getInfoContext().indexOf("\"", count3);
			   System.out.println("----"+count3);
			   System.out.println("----"+count4);
		      for(int i=count3;i<count4;i++){
		    	  imageUrl = imageUrl+info.getInfoContext().charAt(i);
		  }
		      System.out.println("-----------"+imageUrl);
		  }
		   
		   //先修改info表
		   //判断信息内容、发布者、标题是否为空，
			if("".equals(info1.getInfoTitle())||"".equals(info1.getInfoContext())||"".equals(info1.getInfoSender())){
				
				return "error";
			}
		   
  		   b= this.getCommonService().updateObject(info1);
  		   
		   /**
		    * 查看是否为滚动新闻，是滚动新闻更新，不是滚动新闻加入
		    * 
		    */
  		   
		   String hql ="from ImageInfo img where img.info.infoId="+info.getInfoId();
		   
		   System.out.println("+++++========"+hql);
		   List imgList = this.getCommonService().findListByHql(hql, null);
		   
		   Iterator iter = imgList.iterator();
		   
  		   //修改imageInfo表
  		   if(iter.hasNext()){
			   while(iter.hasNext()){
				   
				   ImageInfo imageInfo =(ImageInfo)iter.next();
				   
				   imageInfo.setImageName(info.getInfoTitle());
				   imageInfo.setImageUrl(imageUrl);
				   imageInfo.setInfo(info);
				   
				   this.getCommonService().updateObject(imageInfo);
			   }
  		   }
  		   else{
  			   
  			   ImageInfo imageInfo =new ImageInfo();
			   
			   imageInfo.setImageName(info.getInfoTitle());
			   imageInfo.setImageUrl(imageUrl);
			   imageInfo.setInfo(info);
			   
			   this.getCommonService().saveObject(imageInfo);
  		   }
			  
	   }
		
		
			if(b)
			{
				return "NewsModify";
			}else{
				return  "error";
			}
    	
    }
	
	
	/***
	 *   Delete 删除
	 */
    @SuppressWarnings("unchecked")
	public String Delete() throws Exception{
    	
    	  boolean b1 =false;
    	  boolean b2 =false;
    	
    	  System.out.println(info.getInfoId());
    	  info =(Info) this.getCommonService().findByIntId(info.getInfoId(), "gdut.jmxywz.been.Info");
    	  //先删除图片地址
    	  String hql = "from ImageInfo img  where img.info.infoId="+info.getInfoId();
    	  
    	 
    	  List listImg =this.getCommonService().findListByHql(hql, null);
    	   
    	  Iterator iter =listImg.iterator();
    	  
    	  while(iter.hasNext()){
    		  
    		  ImageInfo img =(ImageInfo)iter.next();
    		  
    		  b1= this.getCommonService().deleteObject(img);
    	  }
    	  
    	 
    	  b2 =this.getCommonService().deleteObject(info);
    	  
    		  return "NewsDelete";
  	
  	  }

	/***
	 *   Delete 删除自己发布的
	 */
    @SuppressWarnings("unchecked")
	 public String DeleteSelf() throws Exception{
    	
	     teacher = (Teacher)ActionContext.getContext().getSession().get(TEACHER_SESSION_KEY);

    	  boolean b1 =false;
    	  boolean b2 =false;
    	
    	  System.out.println(info.getInfoId());
    	  
    	  info =(Info) this.getCommonService().findByIntId(info.getInfoId(), "gdut.jmxywz.been.Info");
    	  
    	  //先删除图片地址
    	  String hql = "from ImageInfo img  where img.info.infoId="+info.getInfoId();
    	  
    	   //判断是否可以删除
     	    if(!info.getTeacherByInfoEditer().getTeacherId().equals(teacher.getTeacherId())){
  			
  			System.out.println("没有删除的权限");
  			
  			return "error";
  	      	}
     	    System.out.println("===="+info.getAuditing());
     	    
  	       if(!"0".equals(info.getAuditing())){
  	   		  
  	   		System.out.println("已通过审核，不能再删除！");
  	   		
  	   		return "error";
  	   	  }
    	  
    	  List listImg =this.getCommonService().findListByHql(hql, null);
    	   
    	  Iterator iter =listImg.iterator();
    	  
    	  while(iter.hasNext()){
    		  
    		  ImageInfo img =(ImageInfo)iter.next();
    		  
    		  b1= this.getCommonService().deleteObject(img);
    	  }
    	  
    	 
    	  b2 =this.getCommonService().deleteObject(info);
    	  
    	  if(b2){
    		  return "NewsDeleteSelf";
    	  }else {
    		  return "error";
    	  }
    	  
  	
  	  }
    
    
	    /***
	     * 
	     * 滚动新闻
	     */

      public  String ScrollNews() throws Exception {
    	  
    	  String hql ="from ImageInfo img where img.info.infoId in(select inf.infoId from Info inf where inf.auditing!=0)";
    	  
    	  nextPage ="newsScrollNews.action" ;
    	  if(!"".equals(where_value)&&where_value!=null){
    		  
    		  System.out.println("++++-- "+where_value);
    		  if(like.equals("like"))
    		  {
             	   hql =hql+"and "+where_search+" like '%"+where_value+"%'";
    		  }else{
    			  hql = hql +"and  "+where_search+" = '"+where_value+"'";
    		  }
    		  
    	  }
    	  //查询条件
    	  searchWhere = "&where_search = "+where_search+"&where_value="+where_value+"&like="+like;
    	  
    	  hql = hql +" order by imageId desc";
    	  
    	  pm = new PageModel();
    	  
    	  System.out.println("============");
    	  
    	  pm=this.getCommonService().findPage(hql, null, currentPage, pageSize, nextPage,searchWhere);
    	  
    	  return "NewsScroll";
      }
      
      /**
       * 查找所有滚动新闻
       * @return
       * @throws Exception
       */
    public  String ScrollNewsAll() throws Exception {
  	  
  	  String hql ="from ImageInfo ";
  	  
  	  nextPage ="newsScrollNewsAll.action" ;

  	  hql = hql +" order by imageId desc";
  	  
  	  pm =new  PageModel();
  	  
  	  pm.setList(this.getCommonService().findListByHql(hql, null));
  	  
  	  return "NewsScrollAll";
    }
	  
	
	
}

	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
